import { httpGet, handleResult } from "./http";
// import { handleResult } from "@/utils/util";
import moment from "moment";
//列表
export async function pageList(params) {
  const url = "/gm_teacher/list";
  return await httpGet(url, params).then(res => {
    res.data.data.list.map(p => {
      if (p.birthday) p.birthday = moment(new Date(p.birthday)).format("YYYY-MM-DD");
      if (p.hiredate) p.hiredate = moment(new Date(p.hiredate)).format("YYYY-MM-DD");
      p.createAt = null;
      p.updateAt = null;
    });
    return res.data.data;
  });
}
//新增
export async function add(data) {
  const url = "/gm_teacher/insert";
  if (data.birthday) data.birthday = moment(new Date(data.birthday)).format("YYYY-MM-DD");
  if (data.hiredate) data.hiredate = moment(new Date(data.hiredate)).format("YYYY-MM-DD");
  return await httpGet(url, data).then(handleResult);
}
//登陆
export async function adminLogin(loginId, password) {
  const url = "/gm_teacher/login";
  return await httpGet(url, { loginId, password }).then(handleResult);
}
//逻辑删除 flag 1物理删除，!1逻辑删除
export async function remove(id, flag = 1) {
  const url = "/gm_teacher/delete";
  return await httpGet(url, { id, flag }).then(handleResult);
}
//更新
export async function update(data) {
  const url = "/gm_teacher/update";
  if (data.birthday) data.birthday = moment(new Date(data.birthday)).format("YYYY-MM-DD");
  if (data.hiredate) data.hiredate = moment(new Date(data.hiredate)).format("YYYY-MM-DD");
  data.createAt = null;
  return await httpGet(url, data).then(handleResult);
}
// //Excel导入教师信息到数据库
// export async function importExcel(teacherFile) {
//   const url = "/gm_teacher/importExcel";
//   return await httpGet(url, { teacherFile }).then(handleResult);
// }

//角色授权
export async function authRole(id, roleIdsStr) {
  const url = "/gm_teacher/auth";
  return await httpGet(url, { id, roleIdsStr }).then(handleResult);
}
//角色批量授权
export async function batchAuthRole(teacherIds, roleIds) {
  const url = "/gm_teacher/auth/batch";
  return await httpGet(url, { teacherIds, roleIds }).then(handleResult);
}
//获取班级教师信息
export async function getHeaderList(classId) {
  const url = "/gm_teacher/list/classId";
  return await httpGet(url, { classId }).then(res => res.data.data);
}
//教师关联班级
export async function bindClass(teacherIds, classIds) {
  const url = "/gm_teacher/bind/class";
  return await httpGet(url, { classIds, teacherIds }).then(res => res.data.data);
}
//修改密码
export async function changePassword(loginId, { password, passwordNew }) {
  const url = "/gm_teacher/change/password";
  return await httpGet(url, { loginId, password, passwordNew }).then(handleResult);
}
